const BASE_URL = 'https://tea.qingnian8.com';
const TIMEOUT = 10000;

const request = (options) => {
  return new Promise((resolve, reject) => {
    const requestOptions = {
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      timeout: TIMEOUT,
      header: {
        'Content-Type': 'application/json',
        'access-key': 'jiayuhang',
        ...options.header,
      },
      data: options.data || {},
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res);
        }
      },
      fail: (err) => {
        reject(err);
      },
      complete: options.complete,
    };

    uni.request(requestOptions);
  });
};

export default request;